# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]:
        if not root:
            return []
        result=[]
        now=[root]
        childs=[]
        direction=True
        while now:
            vals=[]
            while now:
                node=now.pop()
                vals.append(node.val)
                if direction:
                    if node.left:
                        childs.append(node.left)
                    if node.right:
                        childs.append(node.right)
                else:
                    if node.right:
                        childs.append(node.right)  
                    if node.left:
                        childs.append(node.left)                  
            now=childs
            childs=[]
            result.append(vals)
            direction=not direction

        return result

'''
同levelOrder.py
'''